
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.Employee;
import cn.edu.scau.cmi.hombio.domain.Pigsty;
import cn.edu.scau.cmi.hombio.domain.Prevention;
import cn.edu.scau.cmi.hombio.domain.Task;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class PreventionServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected PreventionService service;

	/**
	 * Instantiates a new PreventionServiceTest.
	 *
	 */
	public PreventionServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Save an existing Prevention entity
	* 
	 */
	@Test
	public void savePrevention() {
		// TODO: JUnit - Populate test inputs for operation: savePrevention 
		Prevention prevention = new cn.edu.scau.cmi.hombio.domain.Prevention();
		service.savePrevention(prevention);
	}

	/**
	 * Operation Unit Test
	* Delete an existing Employee entity
	* 
	 */
	@Test
	public void deletePreventionEmployee() {
		// TODO: JUnit - Populate test inputs for operation: deletePreventionEmployee 
		Integer prevention_id = 0;
		Integer related_employee_id = 0;
		Prevention response = null;
		response = service.deletePreventionEmployee(prevention_id, related_employee_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePreventionEmployee
	}

	/**
	 * Operation Unit Test
	* Save an existing Pigsty entity
	* 
	 */
	@Test
	public void savePreventionPigsty() {
		// TODO: JUnit - Populate test inputs for operation: savePreventionPigsty 
		Integer id = 0;
		Pigsty related_pigsty = new cn.edu.scau.cmi.hombio.domain.Pigsty();
		Prevention response = null;
		response = service.savePreventionPigsty(id, related_pigsty);
		// TODO: JUnit - Add assertions to test outputs of operation: savePreventionPigsty
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findPreventionByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findPreventionByPrimaryKey 
		Integer id_1 = 0;
		Prevention response = null;
		response = service.findPreventionByPrimaryKey(id_1);
		// TODO: JUnit - Add assertions to test outputs of operation: findPreventionByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Delete an existing Task entity
	* 
	 */
	@Test
	public void deletePreventionTask() {
		// TODO: JUnit - Populate test inputs for operation: deletePreventionTask 
		Integer prevention_id_1 = 0;
		Integer related_task_id = 0;
		Prevention response = null;
		response = service.deletePreventionTask(prevention_id_1, related_task_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePreventionTask
	}

	/**
	 * Operation Unit Test
	* Delete an existing Pigsty entity
	* 
	 */
	@Test
	public void deletePreventionPigsty() {
		// TODO: JUnit - Populate test inputs for operation: deletePreventionPigsty 
		Integer prevention_id_2 = 0;
		Integer related_pigsty_id = 0;
		Prevention response = null;
		response = service.deletePreventionPigsty(prevention_id_2, related_pigsty_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePreventionPigsty
	}

	/**
	 * Operation Unit Test
	* Save an existing Task entity
	* 
	 */
	@Test
	public void savePreventionTask() {
		// TODO: JUnit - Populate test inputs for operation: savePreventionTask 
		Integer id_2 = 0;
		Task related_task = new cn.edu.scau.cmi.hombio.domain.Task();
		Prevention response = null;
		response = service.savePreventionTask(id_2, related_task);
		// TODO: JUnit - Add assertions to test outputs of operation: savePreventionTask
	}

	/**
	 * Operation Unit Test
	* Delete an existing Prevention entity
	* 
	 */
	@Test
	public void deletePrevention() {
		// TODO: JUnit - Populate test inputs for operation: deletePrevention 
		Prevention prevention_1 = new cn.edu.scau.cmi.hombio.domain.Prevention();
		service.deletePrevention(prevention_1);
	}

	/**
	 * Operation Unit Test
	* Return all Prevention entity
	* 
	 */
	@Test
	public void findAllPreventions() {
		// TODO: JUnit - Populate test inputs for operation: findAllPreventions 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Prevention> response = null;
		response = service.findAllPreventions(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllPreventions
	}

	/**
	 * Operation Unit Test
	* Load an existing Prevention entity
	* 
	 */
	@Test
	public void loadPreventions() {
		Set<Prevention> response = null;
		response = service.loadPreventions();
		// TODO: JUnit - Add assertions to test outputs of operation: loadPreventions
	}

	/**
	 * Operation Unit Test
	* Return a count of all Prevention entity
	* 
	 */
	@Test
	public void countPreventions() {
		Integer response = null;
		response = service.countPreventions();
		// TODO: JUnit - Add assertions to test outputs of operation: countPreventions
	}

	/**
	 * Operation Unit Test
	* Save an existing Employee entity
	* 
	 */
	@Test
	public void savePreventionEmployee() {
		// TODO: JUnit - Populate test inputs for operation: savePreventionEmployee 
		Integer id_3 = 0;
		Employee related_employee = new cn.edu.scau.cmi.hombio.domain.Employee();
		Prevention response = null;
		response = service.savePreventionEmployee(id_3, related_employee);
		// TODO: JUnit - Add assertions to test outputs of operation: savePreventionEmployee
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
